package com.example.design.bilibili.singleton;

/**
 * 饿汉式-静态代码块
 */
public class SingletonTest2 {

    public static void main(String[] args) {
        Singleton2 instance = Singleton2.getInstance();
        Singleton2 instance2 = Singleton2.getInstance();
        System.out.println(instance == instance2);
        System.out.println("instance.hashcode="+instance.hashCode());
        System.out.println("instance2.hashcode="+instance2.hashCode());
    }


}

class Singleton2 {

    private static Singleton2 instance = null;

    private Singleton2() {

    }

    static {
        instance = new Singleton2();
    }

    public static Singleton2 getInstance(){

        return instance;
    }
}
